<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let s1 = Symbol() //生成了Symbol类型的数据
        let s2 = Symbol()
        console.log(s1) //Symbol()
        console.log(s1 === s2) //false

        //1. 不能进行运算
        //console.log(s1 + "abc") //报错

        //2. 显式调用toString()
        console.log(s1.toString() + "abc") //Symbol()abc 没啥用！

        //2. 隐式转换toString()
        if (s1) {
            console.log("执行")
        }

        // let obj = {
        //     name: "twj",
        //     age: 100
        // }
        // let name = Symbol()
        // obj[name] = "hhh"
        // console.log(obj[name]) //hhh

        //避免后期添加新属性时，属性名的冲突
        let keys = {
            name: Symbol(),
            age: Symbol(),
            location: Symbol(),
            test: Symbol()
        }
        let obj = {
            [keys.name]: "twj",
            [keys.age]: 100,
            [keys.location]: "beijing",
            [keys.test]() {
                console.log("test")
            }
        }
        obj.name = "aaaaaa"
        console.log(obj) //{name: 'aaaaaa', Symbol(): 'twj', Symbol(): 100, Symbol(): 'beijing', Symbol(): ƒ}
        obj[keys.test]() //test
    </script>
</body>

</html>